var ns, h = 0;
var app = new Vue({
    el: '#app',
    data: {
        form: {
            lightIsOn: false,
            lightTitle: '打开手电筒'
        }
    },
    methods: {
        moveline: function() {
            var line = $api.byId('line');
            if (h == 250) {
                h = 0;
            } else {
                h = h + 1;
            }
            var hstr = h + 'px';
            document.getElementById('line').style.cssText = "height:" + hstr;
        },
        closeScanner: function() {
            api.sendEvent({
                name: 'do_close_scan',
                extra: {
                    isclose: true
                }
            });
        },
        openWriteNumber: function() {
            api.sendEvent({
                name: 'do_close_scan',
                extra: {
                    canwrite: true
                }
            });
        },
        switchLight: function() {
            var that = this;
            that.form.lightIsOn = !that.form.lightIsOn;
            that.form.lightTitle = that.form.lightIsOn ? '关闭手电筒' : '打开手电筒';
            api.sendEvent({
                name: 'do_switch_light',
                extra: {
                    lightIsOn: that.form.lightIsOn
                }
            });
        },
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    setInterval(function() {
        app.moveline();
    }, 20);
    var header = $api.byId('aui-header');
    $api.css(header, 'border-top: solid 0px #000;');
    api.addEventListener({
        name: 'keyback'
    }, function(ret, err) {
        app.closeScanner();
    });
}